package com.scommunity.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.scommunity.admin.vo.HouseQO;
import com.scommunity.domain.House;
import com.scommunity.mapper.HouseMapper;
import com.scommunity.service.IHouseService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class HouseServiceImpl extends ServiceImpl<HouseMapper, House> implements IHouseService {
    @Autowired
    HouseMapper houseMapper;

    @Override
    public PageInfo<House> findPageInfoByCondition(HouseQO houseQO, int pageNum, int pageSize) {
        PageHelper.startPage(pageNum, pageSize);
        List<House> houses = houseMapper.findPageInfoByCondition(houseQO);
        PageInfo<House> pageInfo = new PageInfo<>(houses);
        return pageInfo;
    }

    @Cacheable(value = "houses")
    @Override
    public List<House> getAll() {
        return houseMapper.findAll();
    }

    @Override
    public List<House> getAllByStatus() {
        return houseMapper.getAllByStatus();
    }

    @CacheEvict(value = "houses", allEntries = true)
    @Override
    public void add(House house) {
        houseMapper.add(house);
    }

    @CacheEvict(value = "houses", allEntries = true)
    @Override
    public void update(House house) {
        houseMapper.update1(house);
    }

    @CacheEvict(value = "houses", allEntries = true)
    @Override
    public void del(String id) {
        houseMapper.del(id);
    }

    @Override
    public int getStatuseById(String id) {
        return houseMapper.getStatuseById(id);
    }

    @Override
    public List<House> getOwnerHouses(String id) {
        return houseMapper.getOwnerHouses(id);
    }

    @Override
    public void updateHouseStatusById(String id, String status) {
        houseMapper.updateHouseStatusById(id, status);
    }

}
